package com.zznj.xzjc.adapter.index;

import android.text.Html;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zznj.xzjc.R;
import com.zznj.xzjc.net.entity.IndexNewXianSuoBean;
import com.zznj.xzjc.utils.StringUtils;
import com.zznj.xzjc.utils.TimeUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import androidx.annotation.Nullable;

/**
 * 描述：添加类的描述
 *
 * @author wx5e48d604c2885118
 * @time 2020/4/7
 */
public class AnYuKuAdapter extends BaseQuickAdapter<IndexNewXianSuoBean, BaseViewHolder> {

    public final static Map<String, String> map = new HashMap() {{
        put("CasePenalty", "行政处罚案件");
        put("CrimeCase", "涉嫌犯罪案件");
        put("CaseJudgment", "刑事判决案件");

        put("EnvironmentSupervise", "环保督察");
        put("PublicOpinion", "互联网舆情");

        put("LeaderHotline", "市长热线");
        put("ComplaintsReport", "投诉举报");
    }};


    public AnYuKuAdapter(int layoutResId, @Nullable List<IndexNewXianSuoBean> data) {
        super(layoutResId, data);
    }

    private String key;
    public void setKey(String key){
        this.key = key;
        notifyDataSetChanged();
    }

    @Override
    protected void convert(BaseViewHolder helper, IndexNewXianSuoBean item) {
        String typeStr = map.get(item.getClassType_s());

        if(StringUtils.isEmpty(key)){
            helper.setText(R.id.tv_title, StringUtils.delHtmlTags(item.getIndexTitle_s()));
        }else{
            helper.setText(R.id.tv_title, Html.fromHtml(StringUtils.delHtmlTags(item.getIndexTitle_s()).replace(key,"<span style='color:red;'>"+key+"</span>")));
        }
        if(!StringUtils.isEmpty(item.getClassType_s())){
            helper.setText(R.id.zsTv, map.get(item.getClassType_s()));
            helper.setVisible(R.id.zsTv,true);
        }else{
            helper.setVisible(R.id.zsTv,false);
        }
        if(item.getClassType_s().equals("CasePenalty") || item.getClassType_s().equals("CrimeCase") ){
            helper.setText(R.id.tv_address, "执法单位：" + StringUtils.toStringForWu(item.getClassType_s().equals("CrimeCase")?item.getYisongOrgName_s():item.getOrgName()));
            helper.setText(R.id.tv_date, "案发时间：" + TimeUtils.getTime(item.getTime_date(), "yyyy-MM-dd"));
        }else if(item.getClassType_s().equals("CaseJudgment")){
            helper.setText(R.id.tv_address, "判决法院：" + StringUtils.toStringForWu(item.getJudgeCourt_s()));
            helper.setText(R.id.tv_date, "判决时间：" + TimeUtils.getTime(item.getTime_date(), "yyyy-MM-dd"));
        }else if(item.getClassType_s().equals("ComplaintsReport")){
            helper.setText(R.id.tv_address, "所属区划：" + StringUtils.toStringForWu(item.getDictionName_s()));
            helper.setText(R.id.tv_date, "举报时间：" + TimeUtils.getTime(item.getTime_date(), "yyyy-MM-dd"));
        }else{
            helper.setText(R.id.tv_address, "所属区划：" + StringUtils.toStringForWu(item.getDictionName_s()));
            helper.setText(R.id.tv_date, "发布时间：" + TimeUtils.getTime(item.getTime_date(), "yyyy-MM-dd"));
        }

    }
}
